package com.hospital.pet.love.lovepethospital.exp;

import com.hospital.pet.love.lovepethospital.resp.Result;
import com.hospital.pet.love.lovepethospital.resp.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author RoselleShaw
 * @create 2024-03-22 16:44
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(ShawCustomException.class)
    public Result<String> exception(ShawCustomException exception) {
        log.error("出现异常：{}", exception.getMessage(), exception);
        return Result.build(null, exception.getCode(), exception.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result<String> otherException(Exception exception) {
        log.error("出现异常：{}", exception.getMessage(), exception);
        return Result.build(null, ResultCodeEnum.UNKNOWN.getCode(), exception.getMessage());
    }

}
